package com.team.bus.module.user.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.team.bus.module.organization.model.Organization;
import com.team.bus.module.role.model.Role;

@Entity
@Table(name = "tuser",schema = "miaoxu")
public class User implements java.io.Serializable {

	private static final long serialVersionUID = 1L;
	private String id;
	private String username;
	private String password;
	private String roleIds;
	private String sex;
	private String tel;                                 //座机
	private String mobile;                              //手机
	private String name;                                //姓名
	private Organization organization;
	private String pinyin;
	private Set<Organization> organizations = new HashSet<Organization>(0);
	private Set<Role> roles = new HashSet<Role>(0);
	private String rolename;
    private String userType;  //用户类型  1中华 2经销商 3定损员
	private String token;
	private String osName;
	private String open_id;
	private String zfnumber;

	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	@Column(name = "ID", unique = true, nullable = false, length = 50)
	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "username", length = 50)
	public String getUsername() {
		return this.username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name = "password", length = 50)
	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "tuser_oganization", schema = "", 
	joinColumns = { @JoinColumn(name = "userid", nullable = false, updatable = false) }, 
	inverseJoinColumns = { @JoinColumn(name = "organizationid", nullable = false, updatable = false) })
	public Set<Organization> getOrganizations() {
		return organizations;
	}

	public void setOrganizations(Set<Organization> organizations) {
		this.organizations = organizations;
	}

	@ManyToMany(fetch = FetchType.LAZY)
	@JoinTable(name = "tuser_role", schema = "", 
	joinColumns = { @JoinColumn(name = "userid", nullable = false, updatable = false) }, 
	inverseJoinColumns = { @JoinColumn(name = "roleid", nullable = false, updatable = false) })
	public Set<Role> getRoles() {
		return roles;
	}

	public void setRoles(Set<Role> roles) {
		this.roles = roles;
	}

	public String getRoleIds() {
		return roleIds;
	}

	public void setRoleIds(String roleIds) {
		this.roleIds = roleIds;
	}

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "oid")
	public Organization getOrganization() {
		return organization;
	}

	public void setOrganization(Organization organization) {
		this.organization = organization;
	}
	
	@Column(name = "sex", length = 5)
	public String getSex() {
		return sex;
	}

	public void setSex(String sex) {
		this.sex = sex;
	}

	@Column(name = "tel", length = 20)
	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	@Column(name = "mobile", length = 20)
	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	@Column(name = "name", length = 50)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "pinyin", length = 50)
	public String getPinyin() {
		return pinyin;
	}

	public void setPinyin(String pinyin) {
		this.pinyin = pinyin;
	}

    @Column(name = "userType", length = 20)
    public String getUserType() {
        return userType;
    }

    public void setUserType(String userType) {
        this.userType = userType;
    }

    @Column(name = "rolename", length = 1000)
	public String getRolename() {
		return rolename;
	}

	public void setRolename(String rolename) {
		this.rolename = rolename;
	}

	@Column(name = "token", unique = true, length = 500)
	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	@Column(name = "osName",  length = 200)
	public String getOsName() {
		return osName;
	}

	public void setOsName(String osName) {
		this.osName = osName;
	}

	@Column(name = "open_id", length = 50)
	public String getOpen_id() {
		return open_id;
	}

	public void setOpen_id(String open_id) {
		this.open_id = open_id;
	}


	@Column(name = "zfnumber", length = 50)
	public String getZfnumber() {
		return zfnumber;
	}

	public void setZfnumber(String zfnumber) {
		this.zfnumber = zfnumber;
	}
}